package com.ueboot.weishop.repository.role;

import com.ueboot.weishop.entity.role.Permission;
import com.ueboot.weishop.entity.role.Resources;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PermissionRepository extends CrudRepository<Permission, Long> {

    @Query("SELECT u.resource FROM Permission u WHERE u.role.role = :role")
    List<Resources> findByRole(@Param("role") String role);


    @Query("SELECT u.resource FROM Permission u WHERE u.role.role = :role AND u.resource.resourceType = :resourceType")
    List<Resources> findByRoleAndResourceType(@Param("role") String role, @Param("resourceType") String resourceType);

}
